package com.kehao.leetcode.jzoffer;

import org.junit.Test;

/**
 * @author Kehao.Chen
 * @version 1.0
 * @date 2022/6/8 15:42
 */
public class JZSolution006 {
    public int[] twoSum(int[] numbers, int target) {
        int[] result = new int[2];
        int i = 0,j = numbers.length -1;

        while (i<j){
            int answer = numbers[i] + numbers[j];
            if(answer>target){
                j--;
            }else if(answer<target){
                i++;
            }else {
                break;
            }
        }

        result[0] = i;
        result[1] = j;
        return result;
    }

    @Test
    public void test01(){
        int[] numbers = {1,2,4,6,10};
        int target = 8;
        int[] result = twoSum(numbers, target);
        System.out.println(result[0]+","+result[1]);
    }
}
